'use strict';

module.exports = {
  up: (queryInterface, Sequelize) => {
    /*
      Add altering commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.createTable('users', { id: Sequelize.INTEGER });
    */
    const { INTEGER, DATE, BOOLEAN, STRING } = Sequelize;

    return queryInterface.createTable('files', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      user: {
        type: INTEGER,
        references: {
          model: 'users',
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE',
      },
      name: STRING(254),
      mime: STRING(254),
      folder_type: BOOLEAN,
      folder: {
        type: INTEGER,
        references: {
          model: 'files',
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE',
      },
      created_at: DATE,
      updated_at: DATE,
    });
  },

  down: queryInterface =>
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
    queryInterface.dropTable('files')
  ,
};
